<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;
use think\Request;
use think\Loader;
class Job extends Rbac
{
 //    项目开发部人员管理
    public function person()
    {
		$select_user = Db::name('user')->where('user_r_id','15')->paginate(10);
		$page = $select_user->render();
		$this->assign('page', $page);
		$this -> assign('select_user',$select_user);
        return $this->fetch('job/person_board');
    }
	
	
	//    项目开发部人员管理
    public function add()
    {
		if(!empty($_POST)){
			$data = [
				'user_phone' => $_POST['user_phone'],
				'user_name' => $_POST['user_name'],
				'user_phone' => $_POST['user_phone'],
				'user_createtime' => strtotime($_POST['user_createtime']),
				'user_text' => $_POST['user_text'],
				'user_password' => sha1(md5("z123456")."mingdaima"),
				'user_r_id' => 15,
			];
			$row = Db::name('user')->insert($data);
			if($row){
				$this->success('添加成功','admin/job/person');
			}
		}
        return $this->fetch('job/person_add');
    }
	public function alter()
    {
		$user_id = request()->param('user_id');
		 $find_user = Db::name('user')->where('user_id',$user_id)->find();
		 $this -> assign('find_user',$find_user);
		if(!empty($_POST)){
			$user_id = $_POST['user_id'];
			$find_user = Db::name('user')->where('user_id',$user_id)->find();
			$data = [
				'user_name' => (!empty($_POST['user_name'])) ? $_POST['user_name'] : $find_user['user_name'],
				'user_phone' => (!empty($_POST['user_phone'])) ? $_POST['user_phone'] : $find_user['user_phone'],
				'user_text' => (!empty($_POST['user_text'])) ? $_POST['user_text'] : $find_user['user_text'],
			];
			
			$update_user = Db::name('user')->where('user_id',$user_id)->update($data);
			if($update_user){
				$this->success('修改成功',"admin/job/person");
			}else{
				$this->error('至少修改一行',"admin/job/alter?user_id=".$user_id );
			}
		}
        return $this->fetch('job/person_alter');
    }
}
